home *** CD-ROM | disk | FTP | other *** search
/ APDL Other Worlds / APDL Other Worlds Collection.iso / SF3000 / Extras / CBlibrary / h / Macros < prev    next >
Encoding:
Text File  |  2003-09-09  |  3.7 KB  |  109 lines

  1. /*
  2.  * CBLibrary - Macros
  3.  * Copyright (C) 2003  Chris Bazley
  4.  *
  5.  * This library is free software; you can redistribute it and/or
  6.  * modify it under the terms of the GNU Lesser General Public
  7.  * License as published by the Free Software Foundation; either
  8.  * version 2.1 of the License, or (at your option) any later version.
  9.  *
  10.  * This library is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  * Lesser General Public License for more details.
  14.  *
  15.  * You should have received a copy of the GNU Lesser General Public
  16.  * License along with this library; if not, write to the Free Software
  17.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  18.  */
  19.  
  20. #ifndef CJBMacros_h
  21. #define CJBMacros_h
  22.  
  23. #include "kernel.h"
  24. #include "msgtrans.h"
  25.  
  26. /* --- Memory --- */
  27. #define FREE(memptr) {free(memptr);memptr=NULL;}
  28.  
  29. /* --- Error reporting/checking --- */
  30. #define THROW(func) {_kernel_oserror *errptr;errptr=func;if(errptr != NULL) return errptr;}
  31.  
  32. #define WRITE_ERR(block, token) strncpy(block.errmess, msgs_lookup(token), sizeof(block.errmess)-1)
  33. #define WRITE_GERR(block, token) strncpy(block.errmess, msgs_global(token), sizeof(block.errmess)-1)
  34.  
  35. #define WRITE_ERR_SUB1(block, token, sub) strncpy(block.errmess, msgs_lookupsub(token, sub, NULL, NULL, NULL), sizeof(block.errmess)-1)
  36.  
  37. /* --- Useful for sprite widths (inc. RH wastage) --- */
  38. #define WORD_ALIGN(width) ((((width) + 3) >> 2) << 2)
  39.  
  40. /* Check for internal error */
  41. #define E_RET(errblk) { \
  42.                         _kernel_oserror *er = errblk; \
  43.                         if(er != NULL) { \
  44.                           err_check_rep(er); \
  45.                           return; \
  46.                         } \
  47.                       }
  48.  
  49. #define E_RETV(errblk, value) { \
  50.                         _kernel_oserror *er = errblk; \
  51.                         if(er != NULL) { \
  52.                           err_check_rep(er); \
  53.                           return value; \
  54.                         } \
  55.                       }
  56.  
  57. /* suppress compiler warnings about unused fn arguments */
  58. #define NOT_USED(x) {x = x;}
  59.  
  60. #define SCALE(value, perc) (((value)*(perc))/100)
  61.  
  62. #define SWAP(a, b) { \
  63.   int temp; \
  64.   temp = a; \
  65.   a = b; \
  66.   b = temp; \
  67. }
  68.  
  69.  
  70. /* This comes out really neat in ARM code, honest! */
  71. #define ABSDIFF(d, x, y) { \
  72.   if(x > y)    \
  73.     d = x - y; \
  74.   else         \
  75.     d = y - x; \
  76. }
  77.  
  78. /* Report internal error */
  79. #define R(token) err_complain(255,msgs_lookup(token))
  80. #define R_RET(token) {err_complain(255,msgs_lookup(token));return;}
  81. #define R_RETV(token, value) {err_complain(255,msgs_lookup(token));return value;}
  82. #define RG(token) err_complain(255,msgs_global(token))
  83. #define RG_RET(token) {err_complain(255,msgs_global(token));return;}
  84. #define RG_RETV(token, value) {err_complain(255,msgs_global(token));return value;}
  85.  
  86. /* Report non-fatal */
  87. #define M(token) err_report(255,msgs_lookup(token))
  88. #define M_RET(token) {err_report(255,msgs_lookup(token));return;}
  89. #define M_RETV(token, value) {err_report(255,msgs_lookup(token));return value;}
  90.  
  91. #define MG(token) err_report(255,msgs_global(token))
  92. #define MG_RET(token) {err_report(255,msgs_global(token));return;}
  93. #define MG_RETV(token, value) {err_report(255,msgs_global(token));return value;}
  94.  
  95. /* Bitfields */
  96. #define FLAG_SET(flags, bit) ((flags & (bit)) != 0)
  97. #define CLEAR_FLAG(bitfield, bit) bitfield = bitfield & (~(bit))
  98. #define SET_FLAG(bitfield, bit) bitfield = bitfield | (bit)
  99.  
  100. /* filetypes */
  101. #define FILETYPE_DIR            0x1000
  102. #define FILETYPE_APP            0x2000
  103. #define FILETYPE_SPRITE         0xff9
  104. #define FILETYPE_TEXT           0xfff
  105. #define FILETYPE_DATA           0xffd
  106. #define FILETYPE_SQUASH         0xfca
  107.  
  108. #endif
  109.